import Vue from 'vue'
import Router from 'vue-router'
import layout from '../views/layout/layout.vue'

const _import = file => require('@/views/' + file + '.vue').default
Vue.use(Router)


const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}


export const routerMap = [ //to be eliminated
  {
    path: '/',
    name: 'main',
    component: layout,
    redirect: '/events',
    hidden: true,
    children: [
      {
        path: '/login',
        name: 'login',
        component: _import('login/login'),
      },
      {
        path: '/events',
        name: 'events',
        component: _import('attendee/events'), 
      },
      {
        path: '/event/:id',
        name: 'event',
        component: _import('attendee/event')
      },
      {
        path: '/myTickets',
        name: 'myTickets',
        component: _import('attendee/myTickets')
      },
      {
        path: '/ticket/:LIFEId',
        name: 'ticket',
        component: _import('attendee/ticket')
      },
      {
        path: '/search',
        name: 'search',
        component: _import('attendee/search')
      },
      {
        path: '/likes',
        name: 'likes',
        component: _import('attendee/likes')
      },
      {
        path: '/createEvent',
        name: 'createEvent',
        component: _import('organizer/createEvent')
      },
      {
        path: '/myEvents',
        name: 'myEvents',
        component: _import('organizer/myEvents')
      },
      {
        path: '/myEvent/:id',
        name: 'myEvent',
        component: _import('organizer/myEvent'),
      },
      {
        path: '/ticketingNotice',
        name: 'ticketingNotice',
        component: _import('attendee/ticketingNotice')
      }
    ]
  },
]

// 实例化vue的时候只挂载constantRouter
export default new Router({
  // mode: 'history', //后端支持可开
  // scrollBehavior: () => ({y: 0}),
  routes: routerMap
})
